home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / RandomDot 1.0.2 / Random Dot Src ƒ / _c / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-21  |  4.1 KB  |  199 lines  |  [TEXT/KAHL]

  1. /* Menu.c - code for handling the menubar in RandomDot
  2.     by David Phillip Oster October 1994 oster@netcom.com
  3.     for:
  4.     Stuart Inglis singlis@waikato.ac.nz
  5.     Department of Computer Science
  6.     University of Waikato, Hamilton, New Zealand
  7.  */
  8. #ifndef __IMAGECOMPRESSION__
  9. #include <ImageCompression.h>
  10. #endif    /* __IMAGECOMPRESSION__ */
  11.  
  12. #ifndef __GESTALTEQU__
  13. #include <GestaltEqu.h>
  14. #endif    /* __GESTALTEQU__ */
  15.  
  16. #ifndef __BALLOONS__
  17. #include <Balloons.h>
  18. #endif    /* __BALLOONS__ */
  19.  
  20. #include "RandomDotMain.h"
  21. #include "RandomDotRes.h"
  22.  
  23. #include "RandomDotWin.h"
  24. #include "RandomDotWinCommands.h"
  25. #include "RandomDotPrint.h"
  26. #include "Error.h"
  27. #include "Menu.h"
  28. #include "Help.h"
  29. #include "Progress.h"
  30. #include "Utils.h"
  31. #include "pgm.h"
  32.  
  33. static Integer myHelpItem = -2;
  34.  
  35.  
  36. /* GetAboutWin - 
  37.  */
  38. static WindowPtr GetAboutWin(void){
  39.     WindowPtr    win;
  40.  
  41.     win = GetNewDialog(rAbout, NIL, (WindowPtr) -1L);
  42.     ShowWindow(win);
  43.     SelectWindow(win);
  44.     return win;
  45. }
  46.  
  47. /* DoAppleMenu - 
  48.  */
  49. static void DoAppleMenu(Integer item){
  50.     Str255        s;
  51.     WindowPtr    win;
  52.  
  53.     if(1 == item){
  54.         win = GetAboutWin();
  55.         SetDialogDefaultItem(win, kOK);
  56.         ModalDialog(NIL, &item);
  57.         DisposeWindow(win);
  58.         if(kOK != item){
  59.             DoHelp();
  60.         }
  61.     }else{
  62.         GetItem(GetMHandle(kAppleMenu), item, s);
  63.         OpenDeskAcc(s);
  64.     }
  65. }
  66.  
  67. /* OpenFileFilterProc - return FALSE if we should show the file.
  68.     i.e., we show PICT files and PGM files
  69.  */
  70. static pascal Boolean OpenFileFilterProc(ParmBlkPtr io){
  71.     return NOT ('PICT' == io->fileParam.ioFlFndrInfo.fdType ||
  72.         IsPGMFile(io));
  73. }
  74.  
  75.  
  76. /* DoOpen - 
  77.  */
  78. void DoOpen(void){
  79.     LongInt                attr;
  80.     StandardFileReply    reply;
  81.     static    OSType    applType[] = { 'PICT' };
  82.     static    FileFilterUPP    fileFilter = NIL;
  83.  
  84.     if(NIL == fileFilter){
  85.         fileFilter = NewFileFilterProc(OpenFileFilterProc);
  86.     }
  87.     if(noErr == Gestalt(gestaltCompressionMgr, &attr)){
  88.         StandardGetFilePreview(fileFilter, 0, applType, &reply);
  89.     }else{
  90.         StandardGetFile(fileFilter, 0, applType, &reply);
  91.     }
  92.     if(reply.sfGood){
  93.         TellError(RandomDotOpen(&reply.sfFile, reply.sfScript));
  94.     }
  95. }
  96.  
  97. void DoCloseWin(WindowPtr win){
  98.     if(NIL == win){
  99.         /* empty */
  100.     }else if(userKind == ((WindowPeek) win)->windowKind){
  101.         RandomDotDisposeWindow(win);
  102.     }else{
  103.         HideWindow(win);
  104.     }
  105. }
  106.  
  107. void DoClose(void){
  108.     WindowPtr    win;
  109.  
  110.     if(NIL != (win = FrontWindow())){
  111.         DoCloseWin(win);
  112.     }
  113. }
  114.  
  115.  
  116. /* DoQuit - do a quit command
  117.  */
  118. void DoQuit(void){
  119.     RecordProgress();
  120.     ExitToShell();
  121. }
  122.  
  123. /* DoFileMenu - 
  124.  */
  125. static void DoFileMenu(Integer item){
  126.     switch(item){
  127.     case kOpenI:        DoOpen();        break;
  128.     case kCloseI:        DoClose();        break;
  129.     case kSaveI:        DoRandomDotSave();        break;
  130.     case kSaveAsI:        DoRandomDotSaveAs();    break;
  131.     case kPageSetupI:    DoRandomDotPageSetup();    break;
  132.     case kPrintI:        DoRandomDotPrint();        break;
  133.     case kQuitI:        DoQuit();        break;
  134.     }
  135. }
  136.  
  137. /* DoEditMenu - 
  138.  */
  139. static void DoEditMenu(Integer item){
  140.     if(NOT SystemEdit(item - 1)){
  141.         switch(item){
  142.         case kUndoI:    break;
  143.         case kCutI:        DoRandomDotCut();    break;
  144.         case kCopyI:    DoRandomDotCopy();    break;
  145.         case kPasteI:    DoRandomDotPaste();    break;
  146.         case kClearI:    break;
  147.             break;
  148.         }
  149.     }
  150. }
  151.  
  152. /* DoRandomDotMenu - 
  153.  */
  154. static void DoRandomDotMenu(Integer item){
  155.     switch(item){
  156.     case kGrayI:        DoRandomDotGrayState();            break;
  157.     case kBWStereoI:    DoRandomDotBWStereoState();        break;
  158.     case kGrayStereoI:    DoRandomDotGrayStereoState();    break;
  159.     case kShimmerI:        DoRandomDotShimmer();            break;
  160.     }
  161. }
  162.  
  163. /* InitHelpItem - augment the help menu with our item, for system 7 only.
  164.  */
  165. void InitHelpItem(void){
  166.     MenuHandle    mh;
  167.     Str255        sName;
  168.  
  169.     if(noErr == HMGetHelpMenuHandle(&mh)){
  170.         GetIndString(sName, kMainStrs, kOurHelpS);
  171.         AppendMenu(mh, sName);
  172.         myHelpItem = CountMItems(mh);
  173.     }
  174. }
  175.  
  176. /* DoHelpMenu - do items added to help menu.
  177.  */
  178. static void DoHelpMenu(Integer item){
  179.     if(item == myHelpItem){
  180.         DoHelp();
  181.     }
  182. }
  183.  
  184. /* GoMenu - do one menu command
  185.  */
  186. void GoMenu(LongInt selector){
  187.     Integer    theLow;
  188.  
  189.     theLow = LoWord(selector);
  190.     switch(HiWord(selector)){
  191.     case kAppleMenu:    DoAppleMenu(theLow);        break;
  192.     case kFileMenu:        DoFileMenu(theLow);            break;
  193.     case kEditMenu:        DoEditMenu(theLow);            break;
  194.     case kRandomDotMenu:DoRandomDotMenu(theLow);    break;
  195.     case kHMHelpMenuID:    DoHelpMenu(theLow);            break;
  196.     }
  197.     HiliteMenu(0);
  198. }
  199.